/**
 *
 * \file CScreen.cpp
 * \brief This file contains the CScreen class implementation.
 * \author Vladimir Klubkov (aka marked)
 *
 * Last changes date:
 * \date 15.03.2011
 *
 * Copyright 2011 Vladimir Klubkov <marked-one@yandex.ru>
 *
 * This file is part of OOXlib.
 *
 * OOXLib is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * OOXlib is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with OOXlib; if not, you can try to find  it here:
 * http://www.gnu.org/licenses/gpl.txt
 * or write to the Free Software Foundation, Inc., 59 Temple Place,
 * Suite 330, Boston, MA  02111-1307  USA
 *
 */

#include "../include/CScreen.h"

namespace OOXlib {

/**
 * Constructor. Calls the base-class constructor.
 * \param File Source code file name.
 * \param iLine Source code line.
 * \param Function Function name.
 */
CScreen::CScreenNumberOutOfBoundsException::CScreenNumberOutOfBoundsException(const ::std::string &File, const int iLine, const ::std::string &Function)
: CException(File, iLine, Function, "Can't create the CScreen object. Wrong screen number was specified. The screen number must be nil or greater, but less than the screens count.") {}
/**
 * Constructor. Becomes the default screen for the current connection.
 * \param pXServerConnection A pointer to the XServerConnection object.
 */
CScreen::CScreen(const CXServerConnection *pXServerConnection)
: m_pXServerConnection(pXServerConnection), m_pScreen(NULL),  m_iScreenNumber(0) {
    if(NULL == m_pXServerConnection) {
        OOXLib_THROW(CNULLPtrConnectionException);
    }
    m_pScreen = ::XDefaultScreenOfDisplay(m_pXServerConnection->Get());
    m_iScreenNumber = ::XScreenNumberOfScreen(m_pScreen);
    m_iScreenWidth = ::XDisplayWidth(m_pXServerConnection->Get(), m_iScreenNumber);
    m_iScreenHeight = ::XDisplayHeight(m_pXServerConnection->Get(), m_iScreenNumber);
}
/**
 * Constructor. Becomes the screen for the current connection.
 * \param pXServerConnection A pointer to the CXServerConnection object.
 * \param iScreenNumber Screen number. Must be valid: nil or greater, but less than the screens count. You can obtain te screens count by calling the GetScreensCount() method of CXServerConnection or CSingleScreenXServerConnection classes.
 */
CScreen::CScreen(const CXServerConnection *pXServerConnection, const int iScreenNumber)
: m_pXServerConnection(pXServerConnection), m_pScreen(NULL),  m_iScreenNumber(0) {
    if(NULL == m_pXServerConnection) {
        OOXLib_THROW(CNULLPtrConnectionException);
    }
    if(!m_pXServerConnection->IsScreenNumberValid(iScreenNumber)) {
        OOXLib_THROW(CScreenNumberOutOfBoundsException);
    }
    m_pScreen = ::XScreenOfDisplay(m_pXServerConnection->Get(), iScreenNumber);
    m_iScreenNumber = iScreenNumber;
    m_iScreenWidth = ::XDisplayWidth(m_pXServerConnection->Get(), m_iScreenNumber);
    m_iScreenHeight = ::XDisplayHeight(m_pXServerConnection->Get(), m_iScreenNumber);
}
/**
 * Returns the screen number.
 * \return The screen number.
 */
CScreen::operator int() const {
    return m_iScreenNumber;
}
/**
 * Returns the screen number.
 * \return The screen number.
 */
int CScreen::Get() const {
    return m_iScreenNumber;
}
/**
 * Returns the screen number.
 * \return The screen number.
 */
int CScreen::GetScreenNumber() const {
    return m_iScreenNumber;
}
/**
 * Returns the screen width.
 * \return Screen width.
 */
int CScreen::ScreenWidth() const {
    return m_iScreenWidth;
}
/**
 * Returns the screen height.
 * \return Screen height.
 */
int CScreen::ScreenHeight() const {
    return m_iScreenHeight;
}
/**
 * Constructor. Calls the base-class constructor.
 * \param File Source code file name.
 * \param iLine Source code line.
 * \param Function Function name.
 */
CNULLPtrScreenException::CNULLPtrScreenException(const ::std::string &File, const int iLine, const ::std::string &Function)
: CException(File, iLine, Function, "NULL was specified as a pointer to the CScreen object.") {}

} // OOXlib
